//
//  UINavigationItem+CustomBarButtonItem.m
//  WZEfengAndEtong
//
//  Created by wanzhao on 16/1/14.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "UINavigationItem+CustomBarButtonItem.h"

@implementation UINavigationItem (CustomBarButtonItem)

- (void)setNewTitle:(NSString *)title
{
    
    
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(47, 0, 226, 44)];
    titleView.tag = 99910;
    
    // Use autoresizing to restrict the bounds to the area that the titleview allows
    
    titleView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
    
    titleView.autoresizesSubviews = YES;
    
    titleView.backgroundColor = [UIColor clearColor];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(00, 0, 226, 44)];
    
    titleLabel.tag = 99901;
    
    titleLabel.backgroundColor = [UIColor clearColor];
    //    titleLabel.backgroundColor = [UIColor redColor];
    titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
    
    titleLabel.textAlignment = NSTextAlignmentLeft;
    
    titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    
    //    titleLabel.textColor = CommonColor;
    titleLabel.textColor  = [UIColor blackColor];
    
    titleLabel.lineBreakMode = NSLineBreakByClipping;
    
    
    titleLabel.autoresizingMask = titleView.autoresizingMask;
    
    
    
    titleLabel.textAlignment = NSTextAlignmentCenter;
    
    titleLabel.text = title;
    
    [titleView addSubview:titleLabel];
    
    self.titleView = titleView;
    
}


- (void)setNewTitleWithActivity:(NSString *)title
{
    
    
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(47, 0, 280, 44)];
    titleView.tag = 99910;
    
    // Use autoresizing to restrict the bounds to the area that the titleview allows
    
    titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
    
    titleView.autoresizesSubviews = YES;
    
    titleView.backgroundColor = [UIColor clearColor];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, 280, 44)];
    
    titleLabel.tag = 99901;
    
    titleLabel.backgroundColor = [UIColor clearColor];
    
    titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
    
    titleLabel.textAlignment = NSTextAlignmentLeft;
    
    titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    
    titleLabel.textColor = CommonColor;
    
    titleLabel.lineBreakMode = NSLineBreakByClipping;
    
    
    titleLabel.autoresizingMask = titleView.autoresizingMask;
    
    
    
    titleLabel.textAlignment = NSTextAlignmentLeft;
    
    titleLabel.text = title;
    
    [titleView addSubview:titleLabel];
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]
                                          initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    [(UIActivityIndicatorView *)indicator startAnimating];
    indicator.tag = 99912;
    indicator.frame = CGRectMake(0, 11, 20, 20);
    [titleView addSubview:indicator];
    [indicator startAnimating];
    self.titleView = titleView;
    
}

- (UIButton *)setNewTitleWithList:(NSString *)title
{
    
    
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 44)];
    
    // Use autoresizing to restrict the bounds to the area that the titleview allows
    
    titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
    
    titleView.autoresizesSubviews = YES;
    
    titleView.backgroundColor = [UIColor clearColor];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 44)];
    
    
    titleLabel.tag = 99901;
    
    titleLabel.backgroundColor = [UIColor clearColor];
    
    titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
    
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.numberOfLines = 0;
    
    titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    
    //    titleLabel.textColor = CommonColor;
    //    titleLabel.textColor = [UIColor blackColor];
    titleLabel.textColor = RGBCOLOR(0xf4, 0xfb, 0xff);
    
    titleLabel.lineBreakMode = NSLineBreakByClipping;
    
    
    titleLabel.autoresizingMask = titleView.autoresizingMask;
    
    
    
    CGRect frame;
    
    
    titleLabel.textAlignment = NSTextAlignmentCenter;
    
    
    
    frame = titleLabel.frame;
    
    frame.size.width = 150;// - maxW0idth * 2;
    
    titleLabel.frame = frame;
    
    
    
    // frame = titleView.frame;
    
    //frame.size.width = 320 - maxWidth * 2;
    
    titleView.frame = frame;
    
    // Set the text
    
    titleLabel.text = title;
    
    // Add as the nav bar's titleview
    
    CGSize titleSize = [title sizeWithFont:titleLabel.font maxSize:CGSizeMake(150.0f - 44.0f, 44.0f)];
    titleLabel.frame = CGRectMake(0, 0, titleSize.width, 44.0f);
    
    UIButton *downBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [downBtn setImage:[UIImage imageNamed:@"depDwonArrow"] forState:UIControlStateNormal];
    [downBtn setImage:[UIImage imageNamed:@"depDwonArrow"] forState:UIControlStateHighlighted];
    downBtn.userInteractionEnabled = YES;
    downBtn.frame = CGRectMake(CGRectGetMaxX(titleLabel.frame), 0, 30.0f, 44.0f);
    [titleView addSubview:downBtn];
    
    titleView.frame = CGRectMake(0, 0, CGRectGetMaxX(downBtn.frame), 44.0f);
    [titleView addSubview:titleLabel];
    
    
    self.titleView = titleView;
    return downBtn;
}
-(void)setNewTitleCenter:(NSString *)title andMessageSettingType:(BOOL)type
{
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 170, 44)];
    
    // Use autoresizing to restrict the bounds to the area that the titleview allows
    
    titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
    
    titleView.autoresizesSubviews = YES;
    
    titleView.backgroundColor = [UIColor clearColor];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 44)];
    
    titleLabel.tag = 99901;
    
    titleLabel.backgroundColor = [UIColor clearColor];
    
    titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
    
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.numberOfLines = 1;
    
    titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    
    //    titleLabel.textColor = CommonColor;
    //    titleLabel.textColor = [UIColor blackColor];
    titleLabel.textColor = RGBCOLOR(0xf4, 0xfb, 0xff);
    
    titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    
    
    titleLabel.autoresizingMask = titleView.autoresizingMask;
    
    
    
    CGRect frame;
    
    
    titleLabel.textAlignment = NSTextAlignmentCenter;
    
    
    
    frame = titleLabel.frame;
    
    frame.size.width = 150;// - maxW0idth * 2;
    
    titleLabel.frame = frame;
    
    
    
    // frame = titleView.frame;
    
    //frame.size.width = 320 - maxWidth * 2;
    
    titleView.frame = frame;
    
    // Set the text
    
    titleLabel.text = title;
    
    // Add as the nav bar's titleview
    
    [titleView addSubview:titleLabel];
    UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(titleLabel.frame), 15, 15 , 15)];
    imageview.image = [UIImage imageNamed:@"alarm---bell"];
    
    [titleView addSubview:imageview];
    imageview.hidden = type;
    
    self.titleView = titleView;
    
}

- (void)setNewTitleCenter:(NSString *)title
{
    
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 44)];
    
    // Use autoresizing to restrict the bounds to the area that the titleview allows
    
    titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
    
    titleView.autoresizesSubviews = YES;
    
    titleView.backgroundColor = [UIColor clearColor];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 44)];
    
    titleLabel.tag = 99901;
    
    titleLabel.backgroundColor = [UIColor clearColor];
    
    titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
    
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.numberOfLines = 1;
    
    titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    
    //    titleLabel.textColor = CommonColor;
    //    titleLabel.textColor = [UIColor blackColor];
    titleLabel.textColor = RGBCOLOR(0xf4, 0xfb, 0xff);
    
    titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    
    
    titleLabel.autoresizingMask = titleView.autoresizingMask;
    
    
    
    CGRect frame;
    
    
    titleLabel.textAlignment = NSTextAlignmentCenter;
    
    
    
    frame = titleLabel.frame;
    
    frame.size.width = 150;// - maxW0idth * 2;
    
    titleLabel.frame = frame;
    
    
    
    // frame = titleView.frame;
    
    //frame.size.width = 320 - maxWidth * 2;
    
    titleView.frame = frame;
    
    // Set the text
    
    titleLabel.text = title;
    
    // Add as the nav bar's titleview
    
    [titleView addSubview:titleLabel];
    self.titleView = titleView;
    
    
}


- (void)setNewAttributeTitleCenter:(NSString *)title  str2:(NSString *)str2 andMessageSettingType:(BOOL)type
{
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 170, 44)];
    
    // Use autoresizing to restrict the bounds to the area that the titleview allows
    
    titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
    
    titleView.autoresizesSubviews = YES;
    
    titleView.backgroundColor = [UIColor clearColor];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 44)];
    
    titleLabel.tag = 99901;
    
    titleLabel.backgroundColor = [UIColor clearColor];
    
    
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.numberOfLines = 0;
    
    titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    
    //    titleLabel.textColor = CommonColor;
    //    titleLabel.textColor = [UIColor blackColor];
    titleLabel.textColor = RGBCOLOR(0xf4, 0xfb, 0xff);
    
    titleLabel.lineBreakMode = NSLineBreakByClipping;
    
    
    titleLabel.autoresizingMask = titleView.autoresizingMask;
    
    
    
    CGRect frame;
    
    
    frame = titleLabel.frame;
    
    frame.size.width = 150;// - maxW0idth * 2;
    
    titleLabel.frame = frame;
    
    
    
    
    titleView.frame = frame;
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@",title,str2]];
    [attr setAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16.0f],NSForegroundColorAttributeName:RGBCOLOR(0xf4, 0xfb, 0xff)} range:NSMakeRange(0, title.length)];
    [attr setAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0f],NSForegroundColorAttributeName:RGBCOLOR(0xf4, 0xfb, 0xff)} range:NSMakeRange(title.length + 1, str2.length)];
    titleLabel.attributedText = attr;
    [titleView addSubview:titleLabel];
    UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(titleLabel.frame), 15, 15 , 15)];
    imageview.image = [UIImage imageNamed:@"alarm---bell"];
    
    [titleView addSubview:imageview];
    imageview.hidden = type;
    self.titleView = titleView;
    
    
}


- (void)setNewTitleImage:(UIImage *)image
{
    UIImageView *imageView = [[UIImageView alloc] init];
    CGRect bounds = imageView.bounds;
    imageView.tag = 99902;
    bounds.size  =  image.size;
    imageView.bounds = bounds;
    self.titleView = imageView;
}





- (void)setLeftItemWithTarget:(id)target
                       action:(SEL)action
                        title:(NSString *)title
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:title forState:UIControlStateNormal];
    
    if (IsIOS7) {
        [button setImageEdgeInsets:UIEdgeInsetsMake(0.0, -30, 0.0, 0.0)];
        [button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, -25, 0.0, 0.0)];
    }else{
        [button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 5, 0.0, 0.0)];
    }
    
    
    self.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
}

- (void)setLeftItemWithTarget:(id)target
                       action:(SEL)action
                        image:(NSString *)image
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateSelected];
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateHighlighted];
    if (IsIOS7) {
        [button setImageEdgeInsets:UIEdgeInsetsMake(0.0, -30, 0.0, 0.0)];
        [button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, -25, 0.0, 0.0)];
    }else{
        [button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 5, 0.0, 0.0)];
    }
    
    self.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
}

- (void)setLeftItemWithTarget:(id)target action:(SEL)action image:(NSString *)image selectedImageName:(NSString*)imageName text:(NSString*)text disabled:(NSString*)disableImage
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateSelected];
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateHighlighted];
    //    [buttonItem.button setImageStr:image forState:UIControlStateNormal];
    
    if (IsIOS7) {
        [button setContentEdgeInsets:UIEdgeInsetsMake(0.0, 0, 0.0, 5)];
    }else{
        [button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 5, 0.0, 0.0)];
    }
    
    
    UIBarButtonItem *negativeSeperator = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    
    //    buttonItem.button.backgroundColor = RedColor;
    //    UIView* vv = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 47, 44)];
    
    
    //    [vv addSubview:buttonItem.button];
    if (leftBarButtonItem) {
        
        //    {
        //        //CGRect rr = self.rightBarButtonItem.customView.frame;
        if(IsIOS7) {
            negativeSeperator.width = - HARDWARE_SCREEN_WIDTH / 20.0;
            //            if (HARDWARE_SCREEN_WIDTH > 320.0f) {
            //                negativeSeperator.width = -20;
            //            } else {
            //                negativeSeperator.width = -16;
            //            }
            ////            leftBarButtonItem.width = 10;
            ////            negativeSeperator.width = 0;
        } else{
            negativeSeperator.width = -5;
            
        }
        self.leftBarButtonItems = [NSArray arrayWithObjects:negativeSeperator, leftBarButtonItem, nil];
    }
    //////        [self setLeftBarButtonItem:self.leftBarButtonItem];
    //////        CGRect frame = self.titleView.frame;
    //////        frame.size.width = HARDWARE_SCREEN_WIDTH-frame.origin.x*2;
    //////        self.titleView.frame = frame;
    ////////        CGRect titleLabelFrame = self.titleView.la
    //////        UILabel *titleLabel = (UILabel *)[self.titleView viewWithTag:99901];
    //////        CGRect titleLabelFrame = titleLabel.frame;
    //////        titleLabelFrame.size.width = frame.size.width;
    //////        titleLabel.frame = titleLabelFrame;
    //////        [self.titleView setNeedsLayout];
    //    }
    //
    
    
    
    if(text){
        
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        
        
        [button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, -self.leftBarButtonItem.customView.frame.size.width, 0.0, 0.0)];
        
        [button setTitle:text forState:UIControlStateSelected];
        
        [button setTitle:text forState:UIControlStateNormal];
        
        [button setTitleColor:RGBCOLORWITH16COLOR(0xf4fbff) forState:UIControlStateSelected];
        
        
        [button setTitleColor:RGBCOLORWITH16COLOR(0xf4fbff) forState:UIControlStateHighlighted];
        
        [button setTitleColor:WhiteColor forState:UIControlStateNormal];
        
    }
    
    if(disableImage){
        [button setImage:[UIImage imageNamed:disableImage] forState:UIControlStateDisabled];
        button.enabled = NO;
    }
    
    
}


-(UIBarButtonItem*)leftBarButtonItem
{
    if(self.leftBarButtonItems.count ==0)return  nil;
    return [self.leftBarButtonItems objectAtIndex:self.leftBarButtonItems.count -1];
}



- (void)setRightItemWithTarget:(id)target
                        action:(SEL)action
                         title:(NSString *)title
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:title forState:UIControlStateNormal];
    
    if (IsIOS7) {
        [button setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0, 0.0, -30.0)];
        [button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 0, 0.0, -25.0)];
    }else{
        [button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 0, 0.0, 5.0)];
    }
    
    self.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
}

- (void)setRightItemWithTarget:(id)target
                        action:(SEL)action
                         title:(NSString *)title font:(UIFont*)font
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:title forState:UIControlStateNormal];
    
    if (IsIOS7) {
        [button setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0, 0.0, -30.0)];
        [button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 0, 0.0, -25.0)];
    }else{
        [button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 0, 0.0, 5.0)];
    }
    
    //    buttonItem.button.font = [UIFont systemFontOfSize:18];
    button.titleLabel.font = font;
    self.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
}


- (void)setRightItemWithTarget:(id)target
                        action:(SEL)action
                         image:(NSString *)image
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateSelected];
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateHighlighted];
    if (IsIOS7) {
        [button setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0, 0.0, -30.0)];
        [button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 0, 0.0, -25.0)];
    }else{
        [button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 0, 0.0, 5.0)];
    }
    
    self.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
}

- (void)setRightItemWithTarget:(id)target action:(SEL)action image:(NSString *)image selectedImageName:(NSString*)imageName text:(NSString*)text
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateSelected];
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateHighlighted];
    
    UIBarButtonItem *negativeSeperator = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    //    buttonItem.button.backgroundColor = RedColor;
    
    if (rightBarButtonItem)
    {
        //CGRect rr = self.rightBarButtonItem.customView.frame;
        if(IsIOS7) {
            negativeSeperator.width = - HARDWARE_SCREEN_WIDTH / 20.0;
            //            if (HARDWARE_SCREEN_WIDTH > 320.0f) {
            //
            //            } else {
            //                negativeSeperator.width = -16;
            //            }
            //            //            leftBarButtonItem.width = 10;
            //            //            negativeSeperator.width = 0;
        } else{
            negativeSeperator.width = -5;
            
        }
        [self setRightBarButtonItems:@[negativeSeperator, rightBarButtonItem]];
    }
    
    if(text){
        
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        
        
        //       [buttonItem.button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, -self.rightBarButtonItem.customView.frame.size.width, 0.0, 0.0)];
        
        //titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
        
        button.titleLabel.font = Font16;
        
        [button setTitle:text forState:UIControlStateSelected];
        
        [button setTitle:text forState:UIControlStateNormal];
        
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
        
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
    }
    
    
    
}
-(void)setRightItemNil
{
    self.rightBarButtonItem = nil;
    self.rightBarButtonItems = nil;
}

-(UIBarButtonItem*)rightBarButtonItem
{
    if(self.rightBarButtonItems.count == 0)return  nil;
    return [self.rightBarButtonItems objectAtIndex:self.rightBarButtonItems.count -1];
}
//@property(nonatomic,retain) UIBarButtonItem *rightBarButtonItem;



@end
